import { hasComponent } from '$lib/ecs';

let actions = [];

/**
 * Registers new action that can be performed if component is present
 */
export const registerAction = (components, name, actionCheck) => {
  actions.push({components, name, actionCheck});
};

/**
 * Get available actions
 */
export const getActions = (world, e) => {
  if (e === undefined)
    return [];
  return actions.filter(({components}) =>
    components.every((component) => hasComponent(world, component, e)));
}
